﻿using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
namespace Gdmec.GameEdiror
{
    public sealed class BuildEditor
    {
        /// <summary>
        /// 生成ab包
        /// </summary>
        /// <param name="path"></param>
        public static void BuildAB(string path)
        {
            var supportTargets = new List<BuildTarget> { BuildTarget.Android, BuildTarget.iOS };
            if (!supportTargets.Contains(EditorUserBuildSettings.activeBuildTarget))
            {
                Debug.LogError("Unsupport " + EditorUserBuildSettings.activeBuildTarget);
                return;
            }

            AssetDatabase.RemoveUnusedAssetBundleNames();
            if (!Directory.Exists(path)) Directory.CreateDirectory(path);

            BuildAssetBundleOptions ops = BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.IgnoreTypeTreeChanges;
            BuildPipeline.BuildAssetBundles(path, ops, EditorUserBuildSettings.activeBuildTarget);

            Debug.Log("BuildAssetBundle:" + path + " OK!");
        }
    }
}
